﻿(function ($) {
	$.fn.pager = function (callback) {
		var container = $(this);
		container.find("span[data-page]").on("click", function () {
			var page = $(this);
			if (page.hasClass('currentPage') || page.hasClass('disabledPrevNext'))
				return;
			if (typeof (callback) == 'function')
				callback(parseInt(page.data('page')));
		});
	};
})(jQuery);

(function ($) {
	$.fn.loadData = function (url, dataParam, callbackParam) {
		var target = this;
		rf.ajax.post(url, dataParam, function (data) {
			$(target).html(data);
			var form = target.find("form");
			if (form != undefined) {
				$(form).removeData("validator");
				$(form).removeData("unobtrusiveValidation");
				$.validator.unobtrusive.parse($(form));
			}
			if ($(data).find("div.validation-summary-errors").length > 0)
				return;
			if (typeof (callbackParam) == 'function')
				callbackParam(data);
		});
	};
})(jQuery);

function resizeNiceScroll() {
	var $htmlElem = $("html");
	if ($htmlElem) {
		$htmlElem.getNiceScroll().resize();
	}
}

function refreshImageUrl(selector, url, width, height, callback) {
	if (selector) {
		var timestamp = new Date().getTime();
		$(selector).attr("src", url + '?' + timestamp);
		$(selector).width(width).height(height);
	}

	if (typeof(callback) == 'function')
		callback();
}